create proc fix_Type
as
IF NOT EXISTS /*bug hasn't been fixed yet*/
(select 1 from [Type] where [Type_Name]='PhoneAlternate' and [TYPE_ID]<>11)
BEGIN 
	CREATE TABLE [dbo].[fixer](
		[id] [int] NULL,
		[label] [varchar](500) NULL
	) ON [PRIMARY]


	insert into fixer(id,[label])Values(10,'Phone')
	insert into fixer(id,[label])Values(11,'PhoneAlternate')
	insert into fixer(id,[label])Values(12,'FaxNumber')
	insert into fixer(id,[label])Values(13,'PagerNumber')
	insert into fixer(id,[label])Values(14,'Street')
	insert into fixer(id,[label])Values(15,'Suite')
	insert into fixer(id,[label])Values(16,'City')
	insert into fixer(id,[label])Values(17,'State')
	insert into fixer(id,[label])Values(18,'Zip')
	insert into fixer(id,[label])Values(19,'Notes')
	insert into fixer(id,[label])Values(21,'MenuWebsite')
	insert into fixer(id,[label])Values(22,'WebLinkType')
	insert into fixer(id,[label])Values(23,'Website')
	insert into fixer(id,[label])Values(24,'Contact')
	insert into fixer(id,[label])Values(25,'Latitude')
	insert into fixer(id,[label])Values(26,'Longitude')
	insert into fixer(id,[label])Values(27,'HotelRating')
	insert into fixer(id,[label])Values(28,'CostRating')
	insert into fixer(id,[label])Values(29,'Hours')
	insert into fixer(id,[label])Values(30,'Price')
	insert into fixer(id,[label])Values(31,'Parking')
	insert into fixer(id,[label])Values(32,'LastChanged')
	insert into fixer(id,[label])Values(33,'altStreet')
	insert into fixer(id,[label])Values(34,'altSuite')
	insert into fixer(id,[label])Values(35,'altCity')
	insert into fixer(id,[label])Values(36,'altState')
	insert into fixer(id,[label])Values(37,'altZip')
	insert into fixer(id,[label])Values(38,'useAlternate')
	insert into fixer(id,[label])Values(39,'CrossStreets')
	insert into fixer(id,[label])Values(40,'OTID')
	insert into fixer(id,[label])Values(41,'CSID')
	insert into fixer(id,[label])Values(42,'useCSAddress')
	insert into fixer(id,[label])Values(43,'useCSPhone')
	insert into fixer(id,[label])Values(44,'useCSCrossStreet')
	insert into fixer(id,[label])Values(45,'useCSWebsite')
	insert into fixer(id,[label])Values(46,'useCSPrice')
	insert into fixer(id,[label])Values(47,'useCSPriceRating')
	insert into fixer(id,[label])Values(48,'useCSHours')
	insert into fixer(id,[label])Values(49,'printTeaser')
	insert into fixer(id,[label])Values(50,'printSynopsis')
	insert into fixer(id,[label])Values(51,'useLatLong')
	insert into fixer(id,[label])Values(52,'BadLocation')
	insert into fixer(id,[label])Values(53,'LastEditUser')
	insert into fixer(id,[label])Values(54,'PhoneExt')
	insert into fixer(id,[label])Values(55,'SuppressAutoRoute')
	insert into fixer(id,[label])Values(56,'EMail')
	insert into fixer(id,[label])Values(57,'DestMap')
	insert into fixer(id,[label])Values(58,'TempLocation')
	insert into fixer(id,[label])Values(59,'CGLatitude')
	insert into fixer(id,[label])Values(60,'CGLongitude')
	insert into fixer(id,[label])Values(61,'UseCustomLatLong')
	insert into fixer(id,[label])Values(62,'isHotel')
	insert into fixer(id,[label])Values(63,'SearchAlias')
	insert into fixer(id,[label])Values(64,'CGCrossStreet')
	insert into fixer(id,[label])Values(65,'useCrossStreet')
	insert into fixer(id,[label])Values(66,'Country')
	insert into fixer(id,[label])Values(67,'AllHotels')
	insert into fixer(id,[label])Values(68,'AllHotelsSet')
	insert into fixer(id,[label])Values(69,'DateAdded')
	insert into fixer(id,[label])Values(70,'FaxOrAlt')
	insert into fixer(id,[label])Values(71,'AltLabel')
	insert into fixer(id,[label])Values(72,'WebsiteProtocol')
	insert into fixer(id,[label])Values(73,'OtherWebProtocol')
	insert into fixer(id,[label])Values(74,'PhoneDigits')
	insert into fixer(id,[label])Values(75,'PhoneAltDigits')
	insert into fixer(id,[label])Values(76,'Building')
	insert into fixer(id,[label])Values(77,'altBuilding')
	insert into fixer(id,[label])Values(78,'showBldg')
	insert into fixer(id,[label])Values(79,'BadCrossStreet')
	insert into fixer(id,[label])Values(80,'CompanyNameSearch')
	insert into fixer(id,[label])Values(81,'PhoneSearch')
	insert into fixer(id,[label])Values(82,'CreateUserID')


	SELECT * 
	INTO [Type_backup] 
	FROM [Type]
	
	DELETE [Type]
	  FROM [Type]
	where [Type_ID] in 
	(
	select id from fixer
	)


	set IDENTITY_INSERT [Type] on 
		insert into [Type]
		([Type_ID]
			  ,[Parent_Type_ID]
			  ,[Type_Name]
			  ,[Enum_Value]
			  ,[Sort]
			  ,[Disabled])
		select 
			  id as [TYPE_ID]
			  ,1 [Parent_Type_ID]
			  ,label as [Type_Name]
			  ,b.[Enum_Value]
			  ,b.[Sort]
			  ,0 [Disabled]
		FROM fixer f
			INNER JOIN  [Type_backup] b
			on f.label=b.[Type_Name]
		ORDER BY f.id
	set IDENTITY_INSERT [Type] off 
	
	DROP TABLE fixer
END
GO
exec fix_Type;

drop proc fix_Type;
